package com.lc.YYGH.user.controller.api;

import com.lc.YYGH.common.result.Result;
import com.lc.YYGH.common.utils.AuthContextHolder;
import com.lc.YYGH.model.message.Consult;
import com.lc.YYGH.model.user.UserInfo;
import com.lc.YYGH.user.service.ConsultService;
import com.lc.YYGH.user.service.UserInfoService;
import com.lc.YYGH.vo.user.LoginVo;
import com.lc.YYGH.vo.user.UserAuthVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@Api(tags="网站用户管理")
@RequestMapping("/api/user")
public class UserInfoApiController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private ConsultService consultService;

    @ApiOperation(value="会员登录")
    @PostMapping("login")
    public Result login(@RequestBody LoginVo loginVo)
    {
        Map<String,Object> info=userInfoService.login(loginVo);
        return Result.success(info);

    }

    @PostMapping("auth/userAuah")
    public Result userAuth(@RequestBody UserAuthVo userAuthVo, HttpServletRequest request)
    {
        userInfoService.userAuth(AuthContextHolder.getUserId(request),userAuthVo);
        return Result.success();

    }
    @GetMapping("auth/getUserInfo")
    public Result getUserInfo(HttpServletRequest request)
    {
        Long userId=AuthContextHolder.getUserId(request);
        UserInfo userInfo=userInfoService.getById(userId);
        return Result.success(userInfo);
    }
    @PostMapping("auth/consult")
    public Result consult(@RequestBody Consult consult)
    {
        consultService.save(consult);
        return Result.success();
    }




}
